<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <!-- 
        setInterval  (执行函数，定时时间间隔，单位是毫秒)
        clearInterval (interval的ID)   //清除定时器
     -->
     <button>清除定时器</button>
    <script>

        var i=1;
        var fun=function(w)
        {
            console.log(i);
            i++;
        }
        var intervalId=setInterval(function(){
            fun()
        },1000)
        console.log('定时id==>',intervalId);
        document.querySelector('button').onclick=function()
        {
            clearInterval(intervalId)
        }
       
    </script>
    
</body>
</html>